// PBM_Processor_1.c ( 265 )

// This work is distributed without any warranty of function , fitness , or safety under the terms of the Electric Document License . Attempt to keep derivative works and contributions under the same license .

// PBM_Processor_3 was a third attempt to write functions that do not exit the segmentation space that forked from PBM_Processor_1 at version # 133 and returned at version # 160 as the main implementation .

// The programme reads the header and determines the width and height of the original image . It reads the image data into an array . It reads from the array directly into the input stream . It applies the cropping , the right flipping , the oblique flipping , the rotation , and the placement in that order . One can force the programme to interpret a different width and height than those specified in the header . This is mostly for testing purposes .
// The programme accepts only a modern PBM ( not byte-per-pixel-coded ) file that has no dimension greater than 32766 pixels .
// The RipRight and RipLeft functions have explicit bit-masking that is not necessary for platforms that cycle in zeros during bit-shift instead of the bits from the other end of the character . gcc on Linux on x86 seems to require the masking .

// We have many arguments . The programme is designed for integration into a larger workflow .
// --Rotate ( number of quarter turns of rotation between zero and three inclusively )
// --Flips ( ( 1 for vertical flipping ) + ( 2 for horizontal flipping ) + ( 4 for oblique flipping ) )
// --Width1 ( Input Width )
// --Height1 ( Input Height )
// --XOffset1 ( Input Horizontal Offset )
// --YOffset1 ( Input Vertical Offset )
// --XTotal1 ( Input Selection Width )
// --YTotal1 ( Input Selection Height )
// --Width2 ( Output Width )
// --Height2 ( Output Height )
// --XOffset2 ( Output Horizontal Offset )
// --YOffset2 ( Output Vertical Offset )
// --XTotal2 ( Output Selection Width )
// --YTotal2 ( Output Selection Width )
// --ManualDim1 ( 1 for setting arbitrary input dimensions )
// --ManualDim2 ( 1 for setting arbitrary output dimensions )
// --Help ( This prints the instructions and continues processing . )
// --help ( This prints the instructions and cancels image processing . )

// Version 157 ( 2010.5.15 ) adds support for a comment line .
// Version 158 ( 2010.5.15 ) corrects problems with the rotation 3 .
// Version 159 ( 2010.5.15 ) is a non-debug form of version 158 .
// Version 160 ( 2010.6.10 ) adds licensing and annotation , sets starting values to zero for future coding safety , and returns to PBM_Processor_1 .
// Version 164 ( 2011.2.21 ) eliminates unnecessary computations in the bit rip functions .
// Version 165 ( 2011.2.22 ) eliminates the need for the math library .
// Version 178 ( 2011.2.23 ) corrects the serious problems introduced by the removal of the math library .
// Version 196 ( 2011.7.5 ) introduces large word optimizations ( not yet enabled by default ) and counter reductions in inner loops for the RipRight2 and RipLeft2 functions .
// Versions 197-199 ( 2011.7.5 ) correct some of the problems introduced by version 196 .
// Version 200 ( 2011.7.5 ) enables 64-bit word support by default ( just for testing ) .
// Versions 201-211 ( 2011.7.5 ) correct some more of the problems introduced by version 196 in the large word code blocks .
// Version 212 ( 2011.7.5 ) corrects an error in the RipUp1 function apparently present since version 164 .
// Version 261 ( 2011.8.16 ) ( in combination with about fifty unofficial preceding versions ) corrects the remaining problems in the little-endian large word optimizations . Tests pass for non-cropped rotations .
// Version 263 ( 2011.8.16 ) annotates the recent changes .
// Version 264 ( 2011.8.17 ) corrects a bad version number in the change log and also removes unnecessary diagnostic output .

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define Support_64_1
unsigned char GetBit1( unsigned char* Start1 , int Pos1 ) ;
unsigned char RipRight1( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Bound1 ) ;
unsigned char Reverse1( unsigned char Input_1 ) ;
inline unsigned char Reversi1( unsigned char Input_1 ) ;
unsigned long long int Reverse_Octet_Bytewise_1( unsigned long long int Input_1 ) ;
unsigned long long int Reverse_Octet_Bitwise_1( unsigned long long int Input_1 ) ;
inline unsigned long long int Reverse_Octet_Bytewise_Inline_1( unsigned long long int Input_1 ) ;
inline unsigned long long int Reverse_Octet_Bitwise_Inline_1( unsigned long long int Input_1 ) ;
unsigned char RipLeft1( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Bound1 ) ;
unsigned char RipDown1( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Bound1 ) ;
unsigned char RipUp1( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Bound1 ) ;
void RipRight2( unsigned char* Start_1 , int Row_Width_1 , int Row_Pos_1 , int Col_Pos_1 , int Iterations_1 ) ;
void RipLeft2( unsigned char* Start_1 , int Row_Width_1 , int Row_Pos_1 , int Col_Pos_1 , int Iterations_1 ) ;
void RipDown2( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Iterations1 ) ;
void RipUp2( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Iterations1 ) ;
unsigned char* NumberFilter2( unsigned char* Input1 , int Cap1 , int Cap2 ) ;
char* NumberFilter3( char* Input1 , int Cap1 , int Cap2 ) ;
int Up_Divide_1( int Dividend , int Divisor ) ;
static unsigned long long int Masks_64_From_Down[] = { 0x0 , 0x101010101010101 , 0x303030303030303 , 0x707070707070707 , 0xF0F0F0F0F0F0F0F , 0x1F1F1F1F1F1F1F1F , 0x3F3F3F3F3F3F3F3F , 0x7F7F7F7F7F7F7F7F , 0xFFFFFFFFFFFFFFFF } ; // This shifts bits in from the least significant end of each octet .
static unsigned long long int Masks_64_From_Up[] = { 0x0 , 0x8080808080808080 , 0xC0C0C0C0C0C0C0C0 , 0xE0E0E0E0E0E0E0E0 , 0xF0F0F0F0F0F0F0F0 , 0xF8F8F8F8F8F8F8F8 , 0xFCFCFCFCFCFCFCFC , 0xFEFEFEFEFEFEFEFE , 0xFFFFFFFFFFFFFFFF } ; // This shifts bits in from the most significant end of each octet .
int Pack_Square_1( char* Input_1 , char* Output_1 , unsigned int Row_Width_1 , unsigned int Row_Width_2 , unsigned int X_Offset_1 , unsigned int Y_Offset_1 , unsigned int X_Total_1 , unsigned int Y_Total_1 ) ;
int Transpose_1( unsigned char * Input_1 , unsigned char * Output_1 ) ;
void PrintHelp1( ) ;
int main( int argc , char** argv ) {
  unsigned char Complex1 = 0 ;
  int CharBuff1 = 0 ;
  unsigned char CharBuff2 = 0 ;
  int State1 = 0 ;
  int Error1 = 0 ;
  int Count1 = 0 ;
  int Count2 = 0 ;
  int Count3 = 0 ;
  int Width1 = 0 ;
  int Height1 = 0 ;
  int CharsPerRow1 = 0 ;
  int Width2 = 0 ;
  int Height2 = 0 ;
  int XOffset1 = 0 ;
  int YOffset1 = 0 ;
  int XTotal1 = 0 ;
  int YTotal1 = 0 ;
  int XOffset2 = 0 ;
  int YOffset2 = 0 ;
  int XTotal2 = 0 ;
  int YTotal2 = 0 ;
  int Rotate2 = 0 ;
  int XBound1 = 0 ;
  int YBound1 = 0 ;
  int XBound2 = 0 ;
  int YBound2 = 0 ;
  int YCount2 = 0 ;
  int XCount2 = 0 ;
  int YCount1 = 0 ;
  int XCount1 = 0 ;
  unsigned char Manual1 = 0 ;
  unsigned char Manual2 = 0 ;
  unsigned char ExtraTransforms1 = ( unsigned char )0 ;
  // We now prepare to read the command line arguments .
  Count1 = 1 ;
  Count2 = 0 ;
  Error1 = 0 ;
  char* ValueBuffer1 = malloc( sizeof( char ) * 8 ) ; // This allocates the space for the processing buffer . No argument ought to be longer than seven characters .
  if ( ValueBuffer1 == NULL ) {
    fprintf( stderr , "Either there are memory problems or something has gone horribly wrong .\n" ) ;
    return 1 ;
  }
  char* ValueBuffer2 ;
  State1 = 0 ;
  while ( Count1 < argc  ) {
    // If a previous argument has indicated that a numerical argument is coming , we prepare for parsing and storing it .
    if ( Count2 > 0 ) {
      ValueBuffer2 = NumberFilter3( argv[ Count1 ] , 7 , 7 ) ;
      if ( ValueBuffer2 > 0 ) {
        if ( strlen( ValueBuffer2 ) > 0 ) {
          Count3 = 0 ;
          switch ( Count2 ) {
            case 1 : sscanf( ValueBuffer2 , "%d" , &Rotate2 ) ; break ;
            case 2 : sscanf( ValueBuffer2 , "%d" , &Count3 ) ; break ;
            case 3 : sscanf( ValueBuffer2 , "%d" , &Width1 ) ; break ;
            case 4 : sscanf( ValueBuffer2 , "%d" , &Height1 ) ; break ;
            case 5 : sscanf( ValueBuffer2 , "%d" , &XOffset1 ) ; break ;
            case 6 : sscanf( ValueBuffer2 , "%d" , &YOffset1 ) ; break ;
            case 7 : sscanf( ValueBuffer2 , "%d" , &XTotal1 ) ; break ;
            case 8 : sscanf( ValueBuffer2 , "%d" , &YTotal1 ) ; break ;
            case 9 : sscanf( ValueBuffer2 , "%d" , &Width2 ) ; break ;
            case 10 : sscanf( ValueBuffer2 , "%d" , &Height2 ) ; break ;
            case 11 : sscanf( ValueBuffer2 , "%d" , &XOffset2 ) ; break ;
            case 12 : sscanf( ValueBuffer2 , "%d" , &YOffset2 ) ; break ;
            case 13 : sscanf( ValueBuffer2 , "%d" , &XTotal2 ) ; break ;
            case 14 : sscanf( ValueBuffer2 , "%d" , &YTotal2 ) ; break ;
            case 15 : sscanf( ValueBuffer2 , "%d" , &Count3 ) ; break ;
            case 16 : sscanf( ValueBuffer2 , "%d" , &Count3 ) ; break ;
          }
          if ( ( ( Count2 == 2 ) || ( Count2 == 15 ) || ( Count2 == 16 ) ) && ( Count3 >=0 ) && ( Count3 < 32 ) ) {
            switch ( Count2 ) {
              case 2 : ExtraTransforms1 = ( unsigned char )Count3 ; break ;
              case 15 : Manual1 = ( unsigned char )Count3 ; break ;
              case 16 : Manual2 = ( unsigned char )Count3 ; break ;
            }
          }
          free( ValueBuffer2 ) ;
          ValueBuffer2 = 0 ;
        }
      }
    }
    // We check for options .
    Count2 = 0 ;
    Count3 = 0 ;
    if ( strcmp( argv[ Count1 ] , "--Rotate" ) == 0 ) {
      Count2 = 1 ;
    } else if ( strcmp( argv[ Count1 ] , "--Flips" ) == 0 ) {
      Count2 = 2 ;
    } else if ( strcmp( argv[ Count1 ] , "--Width1" ) == 0 ) {
      Count2 = 3 ;
    } else if ( strcmp( argv[ Count1 ] , "--Height1" ) == 0 ) {
      Count2 = 4 ;
    } else if ( strcmp( argv[ Count1 ] , "--XOffset1" ) == 0 ) {
      Count2 = 5 ;
    } else if ( strcmp( argv[ Count1 ] , "--YOffset1" ) == 0 ) {
      Count2 = 6 ;
    } else if ( strcmp( argv[ Count1 ] , "--XTotal1" ) == 0 ) {
      Count2 = 7 ;
    } else if ( strcmp( argv[ Count1 ] , "--YTotal1" ) == 0 ) {
      Count2 = 8 ;
    } else if ( strcmp( argv[ Count1 ] , "--Width2" ) == 0 ) {
      Count2 = 9 ;
    } else if ( strcmp( argv[ Count1 ] , "--Height2" ) == 0 ) {
      Count2 = 10 ;
    } else if ( strcmp( argv[ Count1 ] , "--XOffset2" ) == 0 ) {
      Count2 = 11 ;
    } else if ( strcmp( argv[ Count1 ] , "--YOffset2" ) == 0 ) {
      Count2 = 12 ;
    } else if ( strcmp( argv[ Count1 ] , "--XTotal2" ) == 0 ) {
      Count2 = 13 ;
    } else if ( strcmp( argv[ Count1 ] , "--YTotal2" ) == 0 ) {
      Count2 = 14 ;
    } else if ( strcmp( argv[ Count1 ] , "--ManualDim1" ) == 0 ) {
      Count2 = 15 ;
    } else if ( strcmp( argv[ Count1 ] , "--ManualDim2" ) == 0 ) {
      Count2 = 16 ;
    } else if ( strcmp( argv[ Count1 ] , "--Help" ) == 0 ) {
      PrintHelp1( ) ;
    } else if ( strcmp( argv[ Count1 ] , "--help" ) == 0 ) {
      State1 = 0 - 1 ;
      PrintHelp1( ) ;
    }
    Count1 ++ ;
  }
  // We now begin to read the input .
  Count1 = 0 ;
  if ( State1 >= 0 ) {
    CharBuff1 = getchar( ) ;
  } else {
    CharBuff1 = -1 ;
  }
  // We check that the magic number is good .
  if ( CharBuff1 == ( int )'P' ) {
    CharBuff1 = getchar( ) ;
    if ( CharBuff1 == ( int )'4' ) {
      State1 = 1 ;
      CharBuff1 = getchar( ) ;
    } else {
      Error1 = 19 ; // This means that the magic number is wrong .
    }
  } else {
    Error1 = 18 ; // This means that the magic number prefix is wrong . This is generally a bad sign .
  }
  if ( ( CharBuff1 >= 10 ) && ( State1 == 1 ) && ( CharBuff1 <= 32 ) ) {
    State1 = 2 ;
  } else {
    Error1 = 20 ; // This means that the magic number is not followed by white space .
  }
  // We chew through white space and through comments . According to the pbm output that the Gimp produces , there can be a comment ( started by a hash ) on a line after the magic number .
  if ( State1 == 2 ) {
    while ( ( CharBuff1 >= 9 ) && ( CharBuff1 <= 32 ) ) {
      while ( ( CharBuff1 >= 9 ) && ( CharBuff1 <= 32 ) ) {
        CharBuff1 = getchar( ) ;
      }
      if ( CharBuff1 == ( int )( '#' ) ) {
        while ( ( CharBuff1 >= 9 ) && ( CharBuff1 <= 126 ) && ( CharBuff1 != 10 ) && ( CharBuff1 != 13 ) ) {
          CharBuff1 = getchar( ) ;
        }
      }
    }
  }
  // Check that we have a number of some sort .
  if ( ( CharBuff1 >= 48 ) && ( CharBuff1 <= 58 ) && ( State1 == 2 ) ) {
    State1 = 3 ;
  } else {
    Error1 = 22 ; // This means that the white space is followed by something other than a number . Because we measure the height in decimal digits , letters and other non-numeral characters tend to cause problems .
  }
  // We eliminate leading zeroes so that we have no accidental interpretation as octal . These leading zeroes may be cause for concern , but not necessarily for a refusal of the programme to operate .
  while ( ( CharBuff1 == ( int )'0' ) && ( State1 == 3 ) ) {
    CharBuff1 = getchar( ) ;
  }
  if ( ( CharBuff1 >= 48 ) && ( CharBuff1 <= 58 ) && ( State1 == 3 ) ) {
    State1 = 4 ;
  } else {
    Error1 = 23 ; // This means that the zeroes are followed by something other than a number . This means that we either have non-decimal digits or a width of zero pixels . Both promise to pose problems .
  }
  // We chew through the first number , which ought to give the image width by pixel .
  Count1 = 0 ;
  while ( ( CharBuff1 >= 48 ) && ( State1 == 4 ) && ( CharBuff1 <= 58 ) && ( Count1 < 7 ) ) {
    ValueBuffer1[ Count1 ] = ( char )CharBuff1 ;
    Count1 ++ ;
    CharBuff1 = getchar( ) ;
  }
  if ( ( Count1 > 0 ) && ( State1 == 4 ) ) {
    ValueBuffer1[ Count1 ] = ( char )0 ; // We terminate the string .
    if ( ( int )Manual1 < 1 ) {
      sscanf( ValueBuffer1 , "%d" , &Width1 ) ;
    }
    if ( Width1 < 32767 * 4 ) {
      State1 = 5 ;
    } else {
      Error1 = 25 ; // This means that the horizontal dimension is too great . For performance reasons , we want to be able to reference bits by an integer .
    }
  } else {
    Error1 = 24 ; // This means that we have retrieved no digits . As the programme is currently arranged , this error is impossible . The prerequisite of proceeding to step four is that the programme has already retrieved a non-zero decimal digit . This check may be necessary later .
  }
  // We chew through white space .
  while ( ( CharBuff1 >= 9 ) && ( State1 == 5 ) && ( CharBuff1 <= 32 ) ) {
    CharBuff1 = getchar( ) ;
  }
  // Check that we have a number of some sort .
  if ( ( CharBuff1 >= 48 ) && ( CharBuff1 <= 58 ) && ( State1 == 5 ) ) {
    State1 = 6 ;
  } else {
    Error1 = 26 ; // This means that the white space is followed by something other than a number . Because we measure the height in decimal digits , letters and other non-numeral characters tend to cause problems .
  }
  // We eliminate leading zeroes so that we have no accidental interpretation as octal . These leading zeroes may be cause for concern , but not necessarily for a refusal of the programme to operate .
  while ( ( CharBuff1 == ( int )'0' ) && ( State1 == 6 ) ) {
    CharBuff1 = getchar( ) ;
  }
  if ( ( CharBuff1 >= 48 ) && ( CharBuff1 <= 58 ) && ( State1 == 6 ) ) {
    State1 = 7 ;
  } else {
    Error1 = 27 ; // This means that the zeroes are followed by something other than a number . This means that we either have non-decimal digits or a height of zero pixels . Both promise to pose problems .
  }
  // We chew through the second number , which ought to give the image height by pixel .
  Count1 = 0 ;
  while ( ( CharBuff1 >= 48 ) && ( State1 == 7 ) && ( CharBuff1 <= 58 ) && ( Count1 < 7 ) ) {
    ValueBuffer1[ Count1 ] = ( char )CharBuff1 ;
    Count1 ++ ;
    CharBuff1 = getchar( ) ;
  }
  if ( ( Count1 > 0 ) && ( State1 == 7 ) ) {
    ValueBuffer1[ Count1 ] = ( char )0 ; // We terminate the string .
    if ( ( int )Manual1 < 1 ) {
      sscanf( ValueBuffer1 , "%d" , &Height1 ) ;
    }
    if ( Height1 < 32767 * 2 ) {
      State1 = 8 ;
    } else {
      Error1 = 29 ; // This means that the vertical dimension is too great . For performance reasons , we want to be able to reference bits by an integer . The pixel packing gives us an extra factor of eight .
    }
  } else {
    Error1 = 28 ; // This means that we have retrieved no digits . As the programme is currently arranged , this error is impossible . The prerequisite of proceeding to step four is that the programme has already retrieved a non-zero decimal digit . This check may be necessary later .
  }
  free( ValueBuffer1 ) ;
  if ( State1 == 8 ) {
    if ( ( CharBuff1 == 9 ) || ( CharBuff1 == 10 ) || ( CharBuff1 == 13 ) || ( CharBuff1 == 32 ) ) {
      State1 = 9 ; // We need white space before the data begin .
    } else {
      Error1 = 31 ; // This means that the file is incorrectly formatted .
    }
  }
  if ( State1 == 9 ) {
    Count2 = 0 ;
    int YCount1 = 0 ;
    int XCount1 = 0 ;
    CharsPerRow1 = Up_Divide_1( Width1 , 8 ) ;
    // int ByteCount1 = ( CharsPerRow1 * ( Height1 + 1 ) ) ; // We need an extra row because of some previous coding errors that are not quite resolved .
    int ByteCount1 = ( CharsPerRow1 * Height1 ) ;
    int XByteCount1 ;
    unsigned char* Storage1 = malloc( ByteCount1 ) ; // We allocate the main storage array and begin to read in data .
    if ( Storage1 == NULL ) {
      fprintf( stderr , "Either there are memory problems or something has gone horribly wrong .\n" ) ;
      return 1 ;
    }
    Count1 = 0 ;
    YCount1 = 0 ;
    CharBuff1 = getchar( ) ;
    while ( ( Count1 < ByteCount1 ) && ( CharBuff1 != EOF ) ) {
      Storage1[ Count1 ] = ( unsigned char )CharBuff1 ;
      CharBuff1 = getchar( ) ;
      Count1 ++ ;
    }
    // We clear any data remaining in the pipe .
    while ( CharBuff1 != EOF ) {
      CharBuff1 = getchar( ) ;
      if ( CharBuff1 > 0 ) {
        Count2 ++ ;
      }
    }
    // We ensure that every relevant value is positive or zero . For ease of syntax , the integers are signed .
    // We check for the final positioning of the image . We ensure that the selection window fits inside the original image and that the placement window fits inside the final image . The odd rotations flip the dimensions , so they are handled separately .
    if ( ( ( ( Rotate2 == 0 ) || ( Rotate2 == 2 ) ) && ( ( ( ExtraTransforms1 & ( unsigned char )4 ) >> 2 ) == ( unsigned char )0 ) ) || ( ( ( Rotate2 == 1 ) || ( Rotate2 == 3 ) ) && ( ( ( ExtraTransforms1 & ( unsigned char )4 ) >> 2 ) == ( unsigned char )1 ) ) ) {
      if ( ( ( int )Manual2 == 1 ) && ( Width2 < 32767 ) && ( Height2 < 32767 ) ) {
        if ( XTotal1 > ( Width1 - XOffset1 ) ) {
          XTotal1 = ( Width1 - XOffset1 ) ;
        }
        if ( YTotal1 > ( Height1 - YOffset1 ) ) {
          YTotal1 = ( Height1 - YOffset1 ) ;
        }
        if ( XTotal2 > ( Width2 - XOffset2 ) ) {
          XTotal2 = ( Width2 - XOffset2 ) ;
        }
        if ( YTotal2 > ( Height2 - YOffset2 ) ) {
          YTotal2 = ( Height2 - YOffset2 ) ;
        }
        if ( XTotal2 <= XTotal1 ) {
          XTotal1 = XTotal2 ;
        }
        if ( YTotal2 <= YTotal1 ) {
          YTotal1 = YTotal2 ;
        }
      } else {
        Width2 = Width1 ;
        Height2 = Height1 ;
        XOffset1 = 0 ;
        XTotal1 = Width1 ;
        YOffset1 = 0 ;
        YTotal1 = Height1 ;
        XOffset2 = 0 ;
        XTotal2 = Width1 ;
        YOffset2 = 0 ;
        YTotal2 = Height1 ;
      }
    } else if ( ( ( ( Rotate2 == 1 ) || ( Rotate2 == 3 ) ) && ( ( ( ExtraTransforms1 & ( unsigned char )4 ) >> 2 ) == ( unsigned char )0 ) ) || ( ( ( Rotate2 == 0 ) || ( Rotate2 == 2 ) ) && ( ( ( ExtraTransforms1 & ( unsigned char )4 ) >> 2 ) == ( unsigned char )1 ) ) ) {
      if ( ( ( int )Manual2 == 1 ) && ( Width2 < 32767 ) && ( Height2 < 32767 ) ) {
        if ( XTotal1 > ( Width1 - XOffset1 ) ) {
          XTotal1 = ( Width1 - XOffset1 ) ;
        }
        if ( YTotal1 > ( Height1 - YOffset1 ) ) {
          YTotal1 = ( Height1 - YOffset1 ) ;
        }
        if ( XTotal2 > ( Width2 - XOffset2 ) ) {
          XTotal2 = ( Width2 - XOffset2 ) ;
        }
        if ( YTotal2 > ( Height2 - YOffset2 ) ) {
          YTotal2 = ( Height2 - YOffset2 ) ;
        }
        if ( XTotal2 <= YTotal1 ) {
          YTotal1 = XTotal2 ;
        }
        if ( YTotal2 <= XTotal1 ) {
          XTotal1 = YTotal2 ;
        }
      } else {
        Width2 = Height1 ;
        Height2 = Width1 ;
        XOffset1 = 0 ;
        XTotal1 = Width1 ;
        YOffset1 = 0 ;
        YTotal1 = Height1 ;
        XOffset2 = 0 ;
        XTotal2 = Height1 ;
        YOffset2 = 0 ;
        YTotal2 = Width1 ;
      }
    }
    printf( "P4\n%d %d\n" , Width2 , Height2 ) ; // We write the new file header according to the new width and height .
    // We check that we have an image and begin processing .
    if ( ( Width2 > 0 ) && ( Height2 > 0 ) ) {
      unsigned char Selection1 ;
      // There are only eight possible combinations of the X-Y precedence , the X direction , and the Y direction . We select the corresponding transcription configuration .
      if ( Rotate2 == 0 ) {
        switch ( ExtraTransforms1 ) {
          case 0 : Selection1 = 0 ; break ;
          case 1 : Selection1 = 1 ; break ;
          case 2 : Selection1 = 2 ; break ;
          case 3 : Selection1 = 3 ; break ;
          case 4 : Selection1 = 4 ; break ;
          case 5 : Selection1 = 5 ; break ;
          case 6 : Selection1 = 6 ; break ;
          case 7 : Selection1 = 7 ; break ;
        }
      } else if ( Rotate2 == 1 ) {
        switch ( ExtraTransforms1 ) {
          case 0 : Selection1 = 6 ; break ;
          case 1 : Selection1 = 7 ; break ;
          case 2 : Selection1 = 4 ; break ;
          case 3 : Selection1 = 5 ; break ;
          case 4 : Selection1 = 2 ; break ;
          case 5 : Selection1 = 3 ; break ;
          case 6 : Selection1 = 0 ; break ;
          case 7 : Selection1 = 1 ; break ;
        }
      } else if ( Rotate2 == 2 ) {
        switch ( ExtraTransforms1 ) {
          case 0 : Selection1 = 3 ; break ;
          case 1 : Selection1 = 2 ; break ;
          case 2 : Selection1 = 1 ; break ;
          case 3 : Selection1 = 0 ; break ;
          case 4 : Selection1 = 5 ; break ;
          case 5 : Selection1 = 4 ; break ;
          case 6 : Selection1 = 7 ; break ;
          case 7 : Selection1 = 6 ; break ;
        }
      } else if ( Rotate2 == 3 ) {
        switch ( ExtraTransforms1 ) {
          case 0 : Selection1 = 5 ; break ;
          case 1 : Selection1 = 4 ; break ;
          case 2 : Selection1 = 7 ; break ;
          case 3 : Selection1 = 6 ; break ;
          case 4 : Selection1 = 1 ; break ;
          case 5 : Selection1 = 0 ; break ;
          case 6 : Selection1 = 3 ; break ;
          case 7 : Selection1 = 2 ; break ;
        }
      }
      // We begin the transcription . The process is fairly simple and easily comprehended . The choice of directions and such requires some paperwork involving either matrices or a large amount of recursive logic . For performance reasons , each of the eight possibilities is independently coded .
      if ( Selection1 == 0 ) {
        XBound1 = XTotal1 + XOffset1 ;
        YBound1 = YTotal1 + YOffset1 ;
        XBound2 = XTotal2 + XOffset2 ;
        YBound2 = YTotal2 + YOffset2 ;
        YCount2 = 0 ;
        while ( YCount2 < YOffset2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
        YCount1 = YOffset1 ;
        while ( YCount1 < YBound1 ) {
          XCount2 = 0 ;
          while ( XCount2 <= ( XOffset2 - 8 ) ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }	
          XCount1 = XOffset1 ;
          if ( XCount2 < XOffset2 ) {
            if ( ( XBound1 - XCount1 ) < ( 8 - XOffset2 + XCount2 ) ) {
              putchar( ( char )( ( RipRight1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XBound1 - XCount1 - 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 - XBound1 + XCount1 ) ) + ( unsigned char )1 ) ) ) ;
              XCount1 += ( XBound1 - XCount1 ) ;
              XCount2 += 8 ;
            } else {
              putchar( ( char )( ( RipRight1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XBound1 - XCount1 - 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) ) ) ;
              XCount1 += ( 8 - XOffset2 + XCount2 ) ;
              XCount2 += 8 ;
            }
          } else if ( ( XBound1 - XCount1 ) < 8 ) {
              putchar( ( char )( RipRight1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XBound1 - XCount1 - 1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 8 - XBound1 + XCount1 ) ) + ( unsigned char )1 ) ) ) ;
              XCount1 += ( XBound1 - XCount1 ) ;
              XCount2 += 8 ;
          }
          Count1 = ( XBound1 - XCount1 ) / 8 ;
          RipRight2( Storage1 , CharsPerRow1 , YCount1 , XCount1 , Count1 ) ;
          XCount1 += Count1 * 8 ;
          XCount2 += Count1 * 8 ;
          // while ( XCount1 <= ( XBound1 - 8 ) ) {
          //   putchar( ( char )( RipRight1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XBound1 - XCount1 - 1 ) ) ) ;
          //   XCount1 += 8 ;
          //   XCount2 += 8 ;
          // }
          if ( XCount1 < XBound1 ) {
            putchar( ( char )( RipRight1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XBound1 - XCount1 - 1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 8 - XBound1 + XCount1 ) ) + ( unsigned char )1 ) ) ) ;
            XCount1 += ( XBound1 - XCount1 ) ;
            XCount2 += 8 ;
          }
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount1 ++ ;
          YCount2 ++ ;
        }
        while ( YCount2 < Height2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
      }
      if ( Selection1 == 1 ) {
        XBound1 = XTotal1 + XOffset1 ;
        YBound1 = YTotal1 + YOffset1 ;
        XBound2 = XTotal2 + XOffset2 ;
        YBound2 = YTotal2 + YOffset2 ;
        YCount2 = 0 ;
        while ( YCount2 < YOffset2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
        YCount1 = YBound1 - 1 ;
        while ( YCount1 >= YOffset1 ) {
          XCount2 = 0 ;
          while ( XCount2 <= ( XOffset2 - 8 ) ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          XCount1 = XOffset1 ;
          if ( XCount2 < XOffset2 ) {
            if ( ( XBound1 - XCount1 ) < ( 8 - XOffset2 + XCount2 ) ) {
              putchar( ( char )( RipRight1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XBound1 - XCount1 - 1 ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 - XBound1 + XCount1 ) ) + ( unsigned char )1 ) ) ) ;
              XCount1 += ( XBound1 - XCount1 ) ;
              XCount2 += 8 ;
            } else {
              putchar( ( char )( ( RipRight1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XBound1 - XCount1 - 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) ) ) ;
              XCount1 += ( 8 - XOffset2 + XCount2 ) ;
              XCount2 += 8 ;
            }
          } else if ( ( XBound1 - XCount1 ) < 8 ) {
            putchar( ( char )( RipRight1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XBound1 - XCount1 - 1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 8 - XBound1 + XCount1 ) ) + ( unsigned char )1 ) ) ) ;
            XCount1 += ( XBound1 - XCount1 ) ;
            XCount2 += 8 ;
          }
          Count1 = ( XBound1 - XCount1 ) / 8 ;
          RipRight2( Storage1 , CharsPerRow1 , YCount1 , XCount1 , Count1 ) ;
          XCount1 += Count1 * 8 ;
          XCount2 += Count1 * 8 ;
          // while ( XCount1 < ( XBound1 - 8 ) ) {
          //   putchar( ( char )( RipRight1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XBound1 - XCount1 - 1 ) ) ) ;
          //   XCount1 += 8 ;
          //   XCount2 += 8 ;
          // }
          if ( XCount1 < XBound1 ) {
            putchar( ( char )( ( RipRight1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XBound1 - XCount1 - 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) ) ) ;
            XCount1 += ( XBound1 - XCount1 ) ;
            XCount2 += 8 ;
          }
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount1 -- ;
          YCount2 ++ ;
        }
        while ( YCount2 < Height2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
      }
      if ( Selection1 == 2 ) {
        XBound1 = XTotal1 + XOffset1 ;
        YBound1 = YTotal1 + YOffset1 ;
        XBound2 = XTotal2 + XOffset2 ;
        YBound2 = YTotal2 + YOffset2 ;
        YCount2 = 0 ;
        while ( YCount2 < YOffset2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
        YCount1 = YOffset1 ;
        while ( YCount1 < YBound1 ) {
          XCount2 = 0 ;
          while ( XCount2 <= ( XOffset2 - 8 ) ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          XCount1 = XBound1 - 1 ;
          if ( XCount2 < XOffset2 ) {
            if ( ( 1 + XCount1 - XOffset1 ) < ( 8 - XOffset2 + XCount2 ) ) {
              putchar( ( char )( ( RipLeft1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XCount1 + 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - XOffset2 + XCount2 - XCount1 + XOffset1 ) ) + ( unsigned char )1 ) ) ) ;
              XCount1 -= ( 1 + XCount1 - XOffset1 ) ;
              XCount2 += 8 ;
            } else {
              putchar( ( char )( ( RipLeft1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XCount1 + 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) ) ) ;
              XCount1 -= ( 8 - XOffset2 + XCount2 ) ;
              XCount2 += 8 ;
            }
          } else if ( ( XCount1 - XOffset1 ) < 7 ) {
            putchar( ( char )( RipLeft1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XCount1 + 1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - XCount1 + XOffset1 ) ) + ( unsigned char )1 ) ) ) ;
            XCount1 += ( XBound1 - XCount1 ) ;
            XCount2 += 8 ;
          }
          Count1 = ( XCount1 - XOffset1 + 1 ) / 8 ;
          RipLeft2( Storage1 , CharsPerRow1 , YCount1 , XCount1 , Count1 ) ;
          XCount1 -= Count1 * 8 ;
          XCount2 += Count1 * 8 ;
          // while ( XCount1 >= XOffset1 + 7 ) {
          //   putchar( ( char )( RipLeft1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XCount1 + 1 ) ) ) ;
          //   XCount1 -= 8 ;
          //   XCount2 += 8 ;
          // }
          if ( XCount1 >= XOffset1 ) {
            putchar( ( char )( RipLeft1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XCount1 + 1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - XCount1 + XOffset1 ) ) + ( unsigned char )1 ) ) ) ;
            XCount1 -= ( XCount1 - XOffset1 + 1 ) ;
            XCount2 += 8 ;
          }
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount1 ++ ;
          YCount2 ++ ;
        }
        while ( YCount2 < Height2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
      }
      if ( Selection1 == 3 ) {
        XBound1 = XTotal1 + XOffset1 ;
        YBound1 = YTotal1 + YOffset1 ;
        XBound2 = XTotal2 + XOffset2 ;
        YBound2 = YTotal2 + YOffset2 ;
        YCount2 = 0 ;
        while ( YCount2 < YOffset2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
        YCount1 = YBound1 - 1 ;
        while ( YCount1 >= YOffset1 ) {
          XCount2 = 0 ;
          while ( XCount2 <= ( XOffset2 - 8 ) ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          XCount1 = XBound1 - 1 ;
          if ( XCount2 < XOffset2 ) {
            if ( ( 1 + XCount1 - XOffset1 ) < ( 8 - XOffset2 + XCount2 ) ) {
              putchar( ( char )( ( RipLeft1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XCount1 + 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - XOffset2 + XCount2 - XCount1 + XOffset1 ) ) + ( unsigned char )1 ) ) ) ;
              XCount1 -= ( XCount1 - XOffset1 + 1 ) ;
              XCount2 += 8 ;
            } else {
              putchar( ( char )( ( RipLeft1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XCount1 + 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) ) ) ;
              XCount1 -= ( 8 - XOffset2 + XCount2 ) ;
              XCount2 += 8 ;
            }
          } else if ( ( XCount1 - XOffset1 ) < 7 ) {
            putchar( ( char )( RipLeft1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XCount1 + 1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - XCount1 + XOffset1 ) ) + ( unsigned char )1 ) ) ) ;
            XCount1 -= ( XCount1 - XOffset1 + 1 ) ;
            XCount2 += 8 ;
          }
          Count1 = ( XCount1 - XOffset1 + 1 ) / 8 ;
          RipLeft2( Storage1 , CharsPerRow1 , YCount1 , XCount1 , Count1 ) ;
          XCount1 -= Count1 * 8 ;
          XCount2 += Count1 * 8 ;
          // while ( XCount1 >= XOffset1 + 7 ) {
          //   putchar( ( char )( RipLeft1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XCount1 + 1 ) ) ) ;
          //   XCount1 -= 8 ;
          //   XCount2 += 8 ;
          // }
          if ( XCount1 >= XOffset1 ) {
            putchar( ( char )( RipLeft1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , XCount1 + 1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - XCount1 + XOffset1 ) ) + ( unsigned char )1 ) ) ) ;
            XCount1 -= ( XCount1 - XOffset1 + 1 ) ;
            XCount2 += 8 ;
          }
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount1 -- ;
          YCount2 ++ ;
        }
        while ( YCount2 < Height2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
      }
      if ( Selection1 == 4 ) {
        XBound1 = XTotal1 + XOffset1 ;
        YBound1 = YTotal1 + YOffset1 ;
        XBound2 = XTotal2 + XOffset2 ;
        YBound2 = YTotal2 + YOffset2 ;
        YCount2 = 0 ;
        while ( YCount2 < YOffset2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
        XCount1 = XOffset1 ;
        while ( XCount1 < XBound1 ) {
          XCount2 = 0 ;
          while ( XCount2 < ( XOffset2 - 8 ) ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount1 = YOffset1 ;
          if ( XCount2 < XOffset2 ) {
            if ( ( YBound1 - YCount1 ) < ( 8 - XOffset2 + XCount2 ) ) {
              putchar( ( char )( RipDown1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YBound1 - YCount1 ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 - YBound1 + YCount1 ) ) + ( unsigned char )1 ) ) ) ;
              YCount1 += ( YBound1 - YCount1 ) ;
              XCount2 += 8 ;
            } else {
              putchar( ( char )( ( RipDown1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YBound1 - YCount1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) ) ) ;
              YCount1 += ( 8 - XOffset2 + XCount2 ) ;
              XCount2 += 8 ;
            }
          } else if ( ( YBound1 - YCount1 ) < 8 ) {
            putchar( ( char )( ( RipDown1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YBound1 - YCount1 ) >> ( XOffset2 - XCount2 ) ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 8 - YBound1 + YCount1 ) ) + ( unsigned char )1 ) ) ) ;
            YCount1 += ( XBound1 - XCount1 ) ;
            XCount2 += 8 ;
          }
          Count1 = ( YBound1 - YCount1 ) / 8 ;
          RipDown2( Storage1 , CharsPerRow1 , YCount1 , XCount1 , Count1 ) ;
          YCount1 += Count1 * 8 ;
          XCount2 += Count1 * 8 ;
          // while ( YCount1 < ( YBound1 - 8 ) ) {
          //   putchar( ( char )( RipDown1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YBound1 - YCount1 ) ) ) ;
          //   YCount1 += 8 ;
          //   XCount2 += 8 ;
          // }
          if ( YCount1 < YBound1 ) {
            putchar( ( char )( RipDown1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YBound1 - YCount1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 8 - YBound1 + YCount1 ) ) + ( unsigned char )1 ) ) ) ;
            YCount1 += ( YBound1 - YCount1 ) ;
            XCount2 += 8 ;
          }
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          XCount1 ++ ;
          YCount2 ++ ;
        }
        while ( YCount2 < Height2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
      }
      if ( Selection1 == 5 ) {
        XBound1 = XTotal1 + XOffset1 ;
        YBound1 = YTotal1 + YOffset1 ;
        XBound2 = XTotal2 + XOffset2 ;
        YBound2 = YTotal2 + YOffset2 ;
        YCount2 = 0 ;
        while ( YCount2 < YOffset2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
        XCount1 = XOffset1 ;
        while ( XCount1 < XBound1 ) {
          XCount2 = 0 ;
          while ( XCount2 < ( XOffset2 - 8 ) ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount1 = YBound1 - 1 ;
          if ( XCount2 < XOffset2 ) {
            if ( ( 1 + YCount1 - YOffset1 ) < ( 8 - XOffset2 + XCount2 ) ) {
              putchar( ( char )( ( RipUp1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YCount1 + 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - XOffset2 + XCount2 - YCount1 + YOffset1 ) ) + ( unsigned char )1 ) ) ) ;
              YCount1 -= ( 1 + YCount1 - YOffset1 ) ;
              XCount2 += 8 ;
            } else {
              putchar( ( char )( ( RipUp1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YCount1 + 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) ) ) ;
              YCount1 -= ( 8 - XOffset2 + XCount2 ) ;
              XCount2 += 8 ;
            }
          } else if ( ( YCount1 - YOffset1 ) < 7 ) {
            putchar( ( char )( RipUp1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YCount1 + 1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - YCount1 + YOffset1 ) ) + ( unsigned char )1 ) ) ) ;
            YCount1 -= ( YBound1 - YCount1 ) ;
            XCount2 += 8 ;
          }
          Count1 = ( YCount1 - YOffset1 + 1 ) / 8 ;
          RipUp2( Storage1 , CharsPerRow1 , YCount1 , XCount1 , Count1 ) ;
          YCount1 -= Count1 * 8 ;
          XCount2 += Count1 * 8 ;
          // while ( YCount1 >= YOffset1 + 7 ) {
          //   putchar( ( char )( RipUp1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YCount1 + 1 ) ) ) ;
          //   YCount1 -= 8 ;
          //   XCount2 += 8 ;
          // }
          if ( YCount1 >= YOffset1 ) {
            putchar( ( char )( RipUp1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YCount1 + 1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - YCount1 + YOffset1 ) ) + ( unsigned char )1 ) ) ) ;
            YCount1 -= ( YCount1 - YOffset1 + 1 ) ;
            XCount2 += 8 ;
          }
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          XCount1 ++ ;
          YCount2 ++ ;
        }
        while ( YCount2 < Height2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
      }
      if ( Selection1 == 6 ) {
        XBound1 = XTotal1 + XOffset1 ;
        YBound1 = YTotal1 + YOffset1 ;
        XBound2 = XTotal2 + XOffset2 ;
        YBound2 = YTotal2 + YOffset2 ;
        YCount2 = 0 ;
        while ( YCount2 < YOffset2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
        XCount1 = XBound1 - 1 ;
        while ( XCount1 >= XOffset1 ) {
          XCount2 = 0 ;
          while ( XCount2 < ( XOffset2 - 8 ) ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount1 = YOffset1 ;
          if ( XCount2 < XOffset2 ) {
            if ( ( YBound1 - YCount1 ) < ( 8 - XOffset2 + XCount2 ) ) {
              putchar( ( char )( ( RipDown1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YBound1 - YCount1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 8 - XOffset2 + - XCount2 - YBound1 + YCount1 ) ) + ( unsigned char )1 ) ) ) ;
              YCount1 += ( YBound1 - YCount1 ) ;
              XCount2 += 8 ;
            } else {
              putchar( ( char )( ( RipDown1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YBound1 - YCount1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) ) ) ;
              YCount1 += ( 8 - XOffset2 + XCount2 ) ;
              XCount2 += 8 ;
            }
          } else if ( ( YBound1 - YCount1 ) < 8 ) {
            putchar( ( char )( RipDown1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YBound1 - YCount1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 8 - YBound1 + YCount1 ) ) + ( unsigned char )1 ) ) ) ;
            YCount1 += ( XBound1 - XCount1 ) ;
            XCount2 += 8 ;
          }
          Count1 = ( YBound1 - YCount1 ) / 8 ;
          RipDown2( Storage1 , CharsPerRow1 , YCount1 , XCount1 , Count1 ) ;
          YCount1 += Count1 * 8 ;
          XCount2 += Count1 * 8 ;
          // while ( YCount1 < ( YBound1 - 8 ) ) {
          //   putchar( ( char )( RipDown1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YBound1 - YCount1 ) ) ) ;
          //   YCount1 += 8 ;
          //   XCount2 += 8 ;
          // }
          if ( YCount1 < YBound1 ) {
            putchar( ( char )( RipDown1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YBound1 - YCount1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 8 - YBound1 + YCount1 ) ) + ( unsigned char )1 ) ) ) ;
            YCount1 += ( YBound1 - YCount1 ) ;
            XCount2 += 8 ;
          }
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          XCount1 -- ;
          YCount2 ++ ;
        }
        while ( YCount2 < Height2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
      }
      if ( Selection1 == 7 ) {
        XBound1 = XTotal1 + XOffset1 ;
        YBound1 = YTotal1 + YOffset1 ;
        XBound2 = XTotal2 + XOffset2 ;
        YBound2 = YTotal2 + YOffset2 ;
        YCount2 = 0 ;
        while ( YCount2 < YOffset2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
        XCount1 = XBound1 - 1 ;
        while ( XCount1 > XOffset1 ) {
          XCount2 = 0 ;
          while ( XCount2 < ( XOffset2 - 8 ) ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount1 = YBound1 - 1 ;
          if ( XCount2 < XOffset2 ) {
            if ( ( 1 + YCount1 - YOffset1 ) < ( 8 - XOffset2 + XCount2 ) ) {
              putchar( ( char )( ( RipUp1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YCount1 + 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - XOffset2 + XCount2 - YCount1 + YOffset1 ) ) + ( unsigned char )1 ) ) ) ;
              YCount1 -= ( 1 + YCount1 - YOffset1 ) ;
              XCount2 += 8 ;
            } else {
              putchar( ( char )( ( RipUp1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YCount1 + 1 ) >> ( XOffset2 - XCount2 ) ) & ( ( ( unsigned char )1 << ( 8 - XOffset2 + XCount2 ) ) - ( unsigned char )1 ) ) ) ;
              YCount1 -= ( 8 - XOffset2 + XCount2 ) ;
              XCount2 += 8 ;
            }
          } else if ( ( YCount1 - YOffset1 ) < 7 ) {
            putchar( ( char )( RipUp1( Storage1 , CharsPerRow1 , YCount1 , XCount1, YCount1 + 1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - YCount1 + YOffset1 ) ) + ( unsigned char )1 ) ) ) ;
            YCount1 += ( YBound1 - YCount1 ) ;
            XCount2 += 8 ;
          }
          Count1 = ( YCount1 - YOffset1 + 1 ) / 8 ;
          RipUp2( Storage1 , CharsPerRow1 , YCount1 , XCount1 , Count1 ) ;
          YCount1 -= Count1 * 8 ;
          XCount2 += Count1 * 8 ;
          // while ( YCount1 > YOffset1 + 7 ) {
          //   putchar( ( char )( RipUp1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YCount1 + 1 ) ) ) ;
          //   YCount1 -= 8 ;
          //   XCount2 += 8 ;
          // }
          if ( YCount1 >= YOffset1 ) {
            putchar( ( char )( RipUp1( Storage1 , CharsPerRow1 , YCount1 , XCount1 , YCount1 + 1 ) & ( ( unsigned char )255 - ( ( unsigned char )1 << ( 7 - YCount1 + YOffset1 ) ) + ( unsigned char )1 ) ) ) ;
            YCount1 -= ( YCount1 - YOffset1 + 1 ) ;
            XCount2 += 8 ;
          }
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          XCount1 -- ;
          YCount2 ++ ;
        }
        while ( YCount2 < Height2 ) {
          XCount2 = 0 ;
          while ( XCount2 < Width2 ) {
            putchar( ( char )0 ) ;
            XCount2 += 8 ;
          }
          YCount2 ++ ;
        }
      }
    }
    free( Storage1 ) ; // This frees lots of memory .
  }
  // We clear any data remaining in the pipe .
  while ( CharBuff1 != EOF ) {
    CharBuff1 = getchar( ) ;
  }
  return 0 ;
}
unsigned char GetBit1( unsigned char* Start1 , int Pos1 ) {
  return ( ( Start1[ Pos1 / 8 ] & ( ( unsigned char )1 << ( 7 - ( Pos1 % 8 ) ) ) ) >> ( 7 - ( Pos1 % 8 ) ) ) ;
  // This returns a numbered bit ( as the last bit of a character ) from an input character array ( not necessarily a null-terminated string ) . For performance optimization , the function has no bounds checking . Referencing a bit beyond the end of the array shall likely cause a segmentation fault .
}
unsigned char RipRight1( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Bound1 ) {
  int APos1 = ( RowPos1 * RowWidth1 ) + ( ColPos1 / 8 ) ;
  int BPos1 = ColPos1 % 8 ;
  unsigned char Mask1 = ( ( unsigned char )1 << BPos1 ) - ( unsigned char )1 ;
  if ( BPos1 == 0 ) {
      return Start1[ APos1 ] ;
  } else {
    if ( Bound1 >= 8 ) {
      return ( ( ( Start1[ APos1 ] << BPos1 ) & ( ( unsigned char )255 - Mask1 ) ) | ( ( Start1[ APos1 + 1 ] >> ( 8 - BPos1 ) ) & Mask1 ) ) ;
    } else {
      return ( ( Start1[ APos1 ] << BPos1 ) & ( ( unsigned char )255 - Mask1 ) ) ;
    }
  }
  // This returns an eight-bit character from the referenced character array starting at the specified bit in the specified row . For performance optimization , it has no bounds checking . Giving a position beyond the start of the last bit shall likely cause a segmentation fault . This function caches values so that it can minimize integer division operations .
}
/*
void RipRight2( unsigned char* Start_1 , int Row_Width_1 , int Row_Pos_1 , int Col_Pos_1 , int Iterations_1 ) {
  int A_Pos_1 = ( Row_Pos_1 * Row_Width_1 ) + ( Col_Pos_1 / 8 ) ;
  int B_Pos_1 = Col_Pos_1 % 8 ;
  int I_Count_2 ;
  unsigned char Mask_1 = ( ( unsigned char )1 << B_Pos_1 ) - ( unsigned char )1 ;
  I_Count_2 = 0 ;
  while ( I_Count_2 < Iterations_1 ) {
    putchar( ( char )( ( ( Start_1[ A_Pos_1 ] << B_Pos_1 ) & ( ( unsigned char )255 - Mask_1 ) ) | ( ( Start_1[ A_Pos_1 + 1 ] >> ( 8 - B_Pos_1 ) ) & Mask_1 ) ) ) ;
    APos1 ++ ;
    ICount2 ++ ;
  }
  // This returns an eight-bit character from the referenced character array starting at the specified bit in the specified row . For performance optimization , it has no bounds checking . Giving a position beyond the start of the last bit shall likely cause a segmentation fault . This function caches values so that it can minimize integer division operations .
}
*/
void RipRight2( unsigned char* Start_1 , int Row_Width_1 , int Row_Pos_1 , int Col_Pos_1 , int Iterations_1 ) {
  int A_Pos_1 = ( Row_Pos_1 * Row_Width_1 ) + ( Col_Pos_1 / 8 ) ;
  int B_Pos_1 = Col_Pos_1 % 8 ;
  int A_Stop_1 = A_Pos_1 + Iterations_1 ;
  int I_Count_2 ;
  unsigned char Mask_1 = ( ( unsigned char )1 << B_Pos_1 ) - ( unsigned char )1 ;
  unsigned char Char_1 ;
  I_Count_2 = 0 ;
  #ifdef Support_64_1
  // We build a 64-bit mask . There are two ways of doing this ( and possibly even more ) .
  unsigned long long int Long_Long_Mask_1 = ( unsigned long long int )( Mask_1 ) ;
  unsigned long long int Long_Long_Mask_Slide_1 = Long_Long_Mask_1 ;
  int Byte_Count_1 = 0 ;
  // I_Count_2 = 0 ;
  // unsigned char * Copy_Start_1 = &( Long_Long_Mask_1 ) ;
  // while ( I_Count_2 < 8 ) {
  //   Copy_Start_1[ I_Count_2 ] = Mask_1 ;
  //   I_Count_2 ++ ;
  // }
  // unsigned long long int * Long_Long_Start_1 = ( unsigned long long int * )( Start_1 ) ;
  unsigned long long int Long_Long_Temp_1 ;
  I_Count_2 = 0 ;
  if ( B_Pos_1 == 0 ) {
    while ( A_Pos_1 < A_Stop_1 - 7 ) {
      Long_Long_Temp_1 = ( *( ( unsigned long long int * )( Start_1 + A_Pos_1 ) ) ) ;
      // Byte_Count_1 = 0 ;
      // We might need something here if fwrite causes byte alignment problems .
      fwrite( ( char* )( &( Long_Long_Temp_1 ) ) , 1 , 8 , stdout ) ; // We do not catch errors here at the moment .
      A_Pos_1 += 8 ;
    }
  } else {
    // fprintf( stderr , "Shift64\n" ) ;
    Long_Long_Temp_1 = 0xFFU ;
    if ( *( unsigned char *)( & ( Long_Long_Temp_1 ) ) == 0x0U ) { // This handles big-endian things .
      // fprintf( stderr , "BE64\n" ) ;
      while ( A_Pos_1 < A_Stop_1 - 7 ) {
        Long_Long_Temp_1 = ( ( ( *( ( unsigned long long int * )( Start_1 + A_Pos_1 ) ) << B_Pos_1 ) & ~( Long_Long_Mask_1 ) ) | ( ( *( ( unsigned long long int * )( Start_1 + A_Pos_1 ) ) >> ( 8 - B_Pos_1 ) ) & Long_Long_Mask_1 ) ) ;
        // Byte_Count_1 = 0 ;
        // We might need something here if fwrite causes byte alignment problems .
        fwrite( ( char* )( &( Long_Long_Temp_1 ) ) , 1 , 8 , stdout ) ; // We do not catch errors here at the moment .
        A_Pos_1 += 8 ;
      }
    } else if ( *( unsigned char *)( & ( Long_Long_Temp_1 ) ) == 0xFFU ) { // This handles little-endian things .
      // fprintf( stderr , "LE64\n" ) ;
      Long_Long_Mask_Slide_1 = Long_Long_Mask_1 ;
      Long_Long_Mask_Slide_1 |= ( Long_Long_Mask_Slide_1 << 8 ) ;
      Long_Long_Mask_Slide_1 |= ( Long_Long_Mask_Slide_1 << 16 ) ;
      Long_Long_Mask_Slide_1 |= ( Long_Long_Mask_Slide_1 << 32 ) ;
      Long_Long_Mask_1 = Long_Long_Mask_1 << 56 ;
      while ( A_Pos_1 < A_Stop_1 - 7 ) {
        Long_Long_Temp_1 = *( ( unsigned long long int * )( Start_1 + A_Pos_1 ) ) ;
        Long_Long_Temp_1 = Reverse_Octet_Bytewise_Inline_1( Long_Long_Temp_1 ) ; // We flip the bytes before the bit-shift due to the reversed transition on little-endian architectures .
        Long_Long_Temp_1 = ( Long_Long_Temp_1 << B_Pos_1 ) ; // We perform the bit-shift for the main word .
        Long_Long_Temp_1 = Reverse_Octet_Bytewise_Inline_1( Long_Long_Temp_1 ) ; // We now flip the bytes back to their original positions .
        Long_Long_Temp_1 = ( ( Long_Long_Temp_1 & ~( Long_Long_Mask_1 ) ) | ( ( *( ( unsigned long long int * )( Start_1 + A_Pos_1 + 1 ) ) >> ( 8 - B_Pos_1 ) ) & Long_Long_Mask_1 ) ) ; // We now composite with the extra bits from the other byte .
        // Byte_Count_1 = 0 ;
        // We might need something here if fwrite causes byte alignment problems .
        fwrite( ( char* )( &( Long_Long_Temp_1 ) ) , 1 , 8 , stdout ) ; // We do not catch errors here at the moment .
        A_Pos_1 += 8 ;
      }
    }
  }
  #endif
  if ( B_Pos_1 == 0 ) {
    // while ( I_Count_2 < Iterations_1 ) {
    //   putchar( Reversi1( Start_1[ A_Pos_1 ] ) ) ;
    //   A_Pos_1 -- ;
    //   I_Count_2 ++ ;
    // }
    while ( A_Pos_1 < A_Stop_1 ) {
      putchar( Start_1[ A_Pos_1 ] ) ;
      A_Pos_1 ++ ;
    }
  } else {
    // while ( I_Count_2 < Iterations_1 ) {
    //   Char_1 = ( ( ( Start_1[ A_Pos_1 ] << B_Pos_1 ) & ( ( unsigned char )255 - Mask_1 ) ) | ( ( Start_1[ A_Pos_1 + 1 ] >> ( 8 - B_Pos_1 ) ) & Mask_1 ) ) ;
    //   Char_1 = Reversi1( Char_1 ) ;
    //   putchar( Char_1 ) ;
    //   A_Pos_1 -- ;
    //   I_Count_2 ++ ;
    // }
    while ( A_Pos_1 < A_Stop_1 ) {
      Char_1 = ( ( ( Start_1[ A_Pos_1 ] << B_Pos_1 ) & ~( Mask_1 ) ) | ( ( Start_1[ A_Pos_1 + 1 ] >> ( 8 - B_Pos_1 ) ) & Mask_1 ) ) ;
      putchar( Char_1 ) ;
      A_Pos_1 ++ ;
    }
  }
  // This returns an eight-bit character from the referenced character array starting at the specified bit in the specified row and proceeding left . For performance optimization , it has no bounds checking . Giving a position beyond the last bit of the array or before the eighth bit of the array shall likely cause a segmentation fault . This function caches values so that it can minimize integer division operations .
}
unsigned char Reverse1( unsigned char Input_1 ) {
  unsigned char Buffer_1 = Input_1 ;
  Buffer_1 = ( ( Buffer_1 << 1 ) & 0xAAU ) | ( ( Buffer_1 >> 1 ) & 0x55U ) ; // We flip each segment of two .
  Buffer_1 = ( ( Buffer_1 << 2 ) & 0xCCU ) | ( ( Buffer_1 >> 2 ) & 0x33U ) ; // We flip the halves of each segment of four .
  Buffer_1 = ( ( Buffer_1 << 4 ) & 0xF0U ) | ( ( Buffer_1 >> 4 ) & 0xFU ) ; // We flip the halves of the byte .
  return Buffer_1 ;
}
inline unsigned char Reversi1( unsigned char Input_1 ) {
  unsigned char Buffer_1 = Input_1 ;
  Buffer_1 = ( ( Buffer_1 << 1 ) & 0xAAU ) | ( ( Buffer_1 >> 1 ) & 0x55U ) ; // We flip each segment of two .
  Buffer_1 = ( ( Buffer_1 << 2 ) & 0xCCU ) | ( ( Buffer_1 >> 2 ) & 0x33U ) ; // We flip the halves of each segment of four .
  Buffer_1 = ( ( Buffer_1 << 4 ) & 0xF0U ) | ( ( Buffer_1 >> 4 ) & 0xFU ) ; // We flip the halves of the byte .
  return Buffer_1 ;
}
unsigned long long int Reverse_Octet_Bytewise_1( unsigned long long int Input_1 ) {
  unsigned long long int Buffer_1 = Input_1 ;
  Buffer_1 = ( ( Buffer_1 << 8 ) & 0xFF00FF00FF00FF00U ) | ( ( Buffer_1 >> 8 ) & 0xFF00FF00FF00FFU ) ; // We flip each segment of two .
  Buffer_1 = ( ( Buffer_1 << 16 ) & 0xFFFF0000FFFF0000U ) | ( ( Buffer_1 >> 16 ) & 0xFFFF0000FFFFU ) ; // We flip the halves of each segment of four .
  Buffer_1 = ( ( Buffer_1 << 32 ) & 0xFFFFFFFF00000000U ) | ( ( Buffer_1 >> 32 ) & 0xFFFFFFFFU ) ; // We flip the halves of the byte .
  return Buffer_1 ;
}
unsigned long long int Reverse_Octet_Bitwise_1( unsigned long long int Input_1 ) {
  unsigned long long int Buffer_1 = Input_1 ;
  Buffer_1 = ( ( Buffer_1 << 1 ) & 0xAAAAAAAAAAAAAAAAU ) | ( ( Buffer_1 >> 1 ) & 0x5555555555555555U ) ; // We flip each segment of two .
  Buffer_1 = ( ( Buffer_1 << 2 ) & 0xCCCCCCCCCCCCCCCCU ) | ( ( Buffer_1 >> 2 ) & 0x3333333333333333U ) ; // We flip the halves of each segment of four .
  Buffer_1 = ( ( Buffer_1 << 4 ) & 0xF0F0F0F0F0F0F0F0U ) | ( ( Buffer_1 >> 4 ) & 0xF0F0F0F0F0F0F0FU ) ; // We flip the halves of the byte .
  Buffer_1 = ( ( Buffer_1 << 8 ) & 0xFF00FF00FF00FF00U ) | ( ( Buffer_1 >> 8 ) & 0xFF00FF00FF00FFU ) ; // We flip each segment of two .
  Buffer_1 = ( ( Buffer_1 << 16 ) & 0xFFFF0000FFFF0000U ) | ( ( Buffer_1 >> 16 ) & 0xFFFF0000FFFFU ) ; // We flip the halves of each segment of four .
  Buffer_1 = ( ( Buffer_1 << 32 ) & 0xFFFFFFFF00000000U ) | ( ( Buffer_1 >> 32 ) & 0xFFFFFFFFU ) ; // We flip the halves of the byte .
  return Buffer_1 ;
}
inline unsigned long long int Reverse_Octet_Bytewise_Inline_1( unsigned long long int Input_1 ) {
  unsigned long long int Buffer_1 = Input_1 ;
  Buffer_1 = ( ( Buffer_1 << 8 ) & 0xFF00FF00FF00FF00U ) | ( ( Buffer_1 >> 8 ) & 0xFF00FF00FF00FFU ) ; // We flip each segment of two .
  Buffer_1 = ( ( Buffer_1 << 16 ) & 0xFFFF0000FFFF0000U ) | ( ( Buffer_1 >> 16 ) & 0xFFFF0000FFFFU ) ; // We flip the halves of each segment of four .
  Buffer_1 = ( ( Buffer_1 << 32 ) & 0xFFFFFFFF00000000U ) | ( ( Buffer_1 >> 32 ) & 0xFFFFFFFFU ) ; // We flip the halves of the byte .
  return Buffer_1 ;
}
inline unsigned long long int Reverse_Octet_Bitwise_Inline_1( unsigned long long int Input_1 ) {
  unsigned long long int Buffer_1 = Input_1 ;
  Buffer_1 = ( ( Buffer_1 << 1 ) & 0xAAAAAAAAAAAAAAAAU ) | ( ( Buffer_1 >> 1 ) & 0x5555555555555555U ) ; // We flip each segment of two .
  Buffer_1 = ( ( Buffer_1 << 2 ) & 0xCCCCCCCCCCCCCCCCU ) | ( ( Buffer_1 >> 2 ) & 0x3333333333333333U ) ; // We flip the halves of each segment of four .
  Buffer_1 = ( ( Buffer_1 << 4 ) & 0xF0F0F0F0F0F0F0F0U ) | ( ( Buffer_1 >> 4 ) & 0xF0F0F0F0F0F0F0FU ) ; // We flip the halves of the byte .
  Buffer_1 = ( ( Buffer_1 << 8 ) & 0xFF00FF00FF00FF00U ) | ( ( Buffer_1 >> 8 ) & 0xFF00FF00FF00FFU ) ; // We flip each segment of two .
  Buffer_1 = ( ( Buffer_1 << 16 ) & 0xFFFF0000FFFF0000U ) | ( ( Buffer_1 >> 16 ) & 0xFFFF0000FFFFU ) ; // We flip the halves of each segment of four .
  Buffer_1 = ( ( Buffer_1 << 32 ) & 0xFFFFFFFF00000000U ) | ( ( Buffer_1 >> 32 ) & 0xFFFFFFFFU ) ; // We flip the halves of the byte .
  return Buffer_1 ;
}
unsigned char RipLeft1( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Bound1 ) {
  int APos1 = ( RowPos1 * RowWidth1 ) + ( ( ColPos1 + 1 ) / 8 ) - 1 ; // Division does not work as expected , requiring this simple and happy hack .
  int BPos1 = ( ColPos1 + 1 ) % 8 ;
  unsigned char Char1 = ( char )0 ;
  unsigned char Mask1 = ( ( unsigned char )1 << BPos1 ) - ( unsigned char )1 ;
  if ( BPos1 == 0 ) {
    if ( Bound1 >= 8 ) {
      Char1 = Start1[ APos1 ] ;
    } else {
      Char1 = ( char )0 ;
    }
  } else {
    if ( Bound1 >= 8 ) {
      Char1 = ( ( ( Start1[ APos1 ] << BPos1 ) & ( ( unsigned char )255 - Mask1 ) ) | ( ( Start1[ APos1 + 1 ] >> ( 8 - BPos1 ) ) & Mask1 ) ) ;
    } else {
      Char1 = ( ( Start1[ APos1 + 1 ] >> ( 8 - BPos1 ) ) & Mask1 ) ;
    }
  }
  Char1 = Reversi1( Char1 ) ;
  return Char1 ;
  // This returns an eight-bit character from the referenced character array starting at the specified bit in the specified row and proceeding left . For performance optimization , it has no bounds checking . Giving a position beyond the last bit of the array or before the eighth bit of the array shall likely cause a segmentation fault . This function caches values so that it can minimize integer division operations .
}
void RipLeft2( unsigned char* Start_1 , int Row_Width_1 , int Row_Pos_1 , int Col_Pos_1 , int Iterations_1 ) {
  int A_Pos_1 = ( Row_Pos_1 * Row_Width_1 ) + ( ( Col_Pos_1 + 1 ) / 8 ) - 1 ; // Division does not work as expected , requiring this simple and happy hack .
  int B_Pos_1 = ( Col_Pos_1 + 1 ) % 8 ;
  int A_Stop_1 = A_Pos_1 - Iterations_1 ;
  int I_Count_2 ;
  unsigned char Mask_1 = ( ( unsigned char )1 << B_Pos_1 ) - ( unsigned char )1 ;
  unsigned char Char_1 ;
  I_Count_2 = 0 ;
  #ifdef Support_64_1
  // We build a 64-bit mask . There are two ways of doing this ( and possibly even more ) .
  unsigned long long int Long_Long_Mask_1 = ( unsigned long long int )( Mask_1 ) ;
  unsigned long long int Long_Long_Mask_Slide_1 = Long_Long_Mask_1 ;
  int Byte_Count_1 = 0 ;
  // I_Count_2 = 0 ;
  // unsigned char * Copy_Start_1 = &( Long_Long_Mask_1 ) ;
  // while ( I_Count_2 < 8 ) {
  //   Copy_Start_1[ I_Count_2 ] = Mask_1 ;
  //   I_Count_2 ++ ;
  // }
  // unsigned long long int * Long_Long_Start_1 = ( unsigned long long int * )( Start_1 ) ;
  unsigned long long int Long_Long_Temp_1 ;
  I_Count_2 = 0 ;
  if ( B_Pos_1 == 0 ) {
    while ( A_Pos_1 > A_Stop_1 + 7 ) {
      Long_Long_Temp_1 = Reverse_Octet_Bitwise_1( *( ( unsigned long long int * )( Start_1 + A_Pos_1 - 7 ) ) ) ;
      // Byte_Count_1 = 0 ;
      // We might need something here if fwrite causes byte alignment problems .
      fwrite( ( char* )( &( Long_Long_Temp_1 ) ) , 1 , 8 , stdout ) ; // We do not catch errors here at the moment .
      A_Pos_1 -= 8 ;
    }
  } else {
    // fprintf( stderr , "Shift64\n" ) ;
    Long_Long_Temp_1 = 0xFFU ;
    if ( *( unsigned char *)( & ( Long_Long_Temp_1 ) ) == 0x0U ) { // This handles big-endian things .
      // fprintf( stderr , "BE64\n" ) ;
      while ( A_Pos_1 > A_Stop_1 + 8 ) {
        Long_Long_Temp_1 = ( ( ( *( ( unsigned long long int * )( Start_1 + A_Pos_1 - 7 ) ) << B_Pos_1 ) & ~( Long_Long_Mask_1 ) ) | ( ( *( ( unsigned long long int * )( Start_1 + A_Pos_1 - 6 ) ) >> ( 8 - B_Pos_1 ) ) & Long_Long_Mask_1 ) ) ;
        Long_Long_Temp_1 = Reverse_Octet_Bitwise_1( Long_Long_Temp_1 ) ;
        // Byte_Count_1 = 0 ;
        // We might need something here if fwrite causes byte alignment problems .
        fwrite( ( char* )( &( Long_Long_Temp_1 ) ) , 1 , 8 , stdout ) ; // We do not catch errors here at the moment .
        A_Pos_1 -= 8 ;
      }
    } else if ( *( unsigned char *)( & ( Long_Long_Temp_1 ) ) == 0xFFU ) { // This handles little-endian things .
      // fprintf( stderr , "LE64\n" ) ;
      Long_Long_Mask_Slide_1 = Long_Long_Mask_1 ;
      Long_Long_Mask_Slide_1 |= ( Long_Long_Mask_Slide_1 << 8 ) ;
      Long_Long_Mask_Slide_1 |= ( Long_Long_Mask_Slide_1 << 16 ) ;
      Long_Long_Mask_Slide_1 |= ( Long_Long_Mask_Slide_1 << 32 ) ;
      Long_Long_Mask_1 = Long_Long_Mask_1 << 56 ;
      while ( A_Pos_1 > A_Stop_1 + 7 ) {
        Long_Long_Temp_1 = *( ( unsigned long long int * )( Start_1 + A_Pos_1 - 7 ) ) ;
        Long_Long_Temp_1 = Reverse_Octet_Bytewise_Inline_1( Long_Long_Temp_1 ) ; // We flip the bytes before the bit-shift due to the reversed transition on little-endian architectures .
        Long_Long_Temp_1 = ( Long_Long_Temp_1 << B_Pos_1 ) ; // We perform the bit-shift for the main word .
        Long_Long_Temp_1 = Reverse_Octet_Bytewise_Inline_1( Long_Long_Temp_1 ) ; // We now flip the bytes back to their original positions .
        Long_Long_Temp_1 = ( ( Long_Long_Temp_1 & ~( Long_Long_Mask_1 ) ) | ( ( *( ( unsigned long long int * )( Start_1 + A_Pos_1 - 6 ) ) >> ( 8 - B_Pos_1 ) ) & 0xFF00000000000000U ) ) ; // We now composite with the extra bits from the other byte .
        Long_Long_Temp_1 = Reverse_Octet_Bitwise_Inline_1( Long_Long_Temp_1 ) ;
        // Byte_Count_1 = 0 ;
        // We might need something here if fwrite causes byte alignment problems .
        fwrite( ( char* )( &( Long_Long_Temp_1 ) ) , 1 , 8 , stdout ) ; // We do not catch errors here at the moment .
        A_Pos_1 -= 8 ;
      }
    }
  }
  #endif
  if ( B_Pos_1 == 0 ) {
    // while ( I_Count_2 < Iterations_1 ) {
    //   putchar( Reversi1( Start_1[ A_Pos_1 ] ) ) ;
    //   A_Pos_1 -- ;
    //   I_Count_2 ++ ;
    // }
    while ( A_Pos_1 > A_Stop_1 ) {
      putchar( Reversi1( Start_1[ A_Pos_1 ] ) ) ;
      A_Pos_1 -- ;
    }
  } else {
    // while ( I_Count_2 < Iterations_1 ) {
    //   Char_1 = ( ( ( Start_1[ A_Pos_1 ] << B_Pos_1 ) & ( ( unsigned char )255 - Mask_1 ) ) | ( ( Start_1[ A_Pos_1 + 1 ] >> ( 8 - B_Pos_1 ) ) & Mask_1 ) ) ;
    //   Char_1 = Reversi1( Char_1 ) ;
    //   putchar( Char_1 ) ;
    //   A_Pos_1 -- ;
    //   I_Count_2 ++ ;
    // }
    while ( A_Pos_1 > A_Stop_1 ) {
      Char_1 = ( ( ( Start_1[ A_Pos_1 ] << B_Pos_1 ) & ~( Mask_1 ) ) | ( ( Start_1[ A_Pos_1 + 1 ] >> ( 8 - B_Pos_1 ) ) & Mask_1 ) ) ;
      putchar( Reversi1( Char_1 ) ) ;
      A_Pos_1 -- ;
    }
  }
  // This returns an eight-bit character from the referenced character array starting at the specified bit in the specified row and proceeding left . For performance optimization , it has no bounds checking . Giving a position beyond the last bit of the array or before the eighth bit of the array shall likely cause a segmentation fault . This function caches values so that it can minimize integer division operations .
}
unsigned char RipDown1( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Bound1 ) {
  int APos1 = ( RowPos1 ) * RowWidth1 + ( ColPos1 / 8 ) ;
  int BPos1 = ColPos1 % 8 ;
  int ICount1 ;
  int IncrementCap1 = 8 ;
  if ( Bound1 < 8 ) { 
    IncrementCap1 = Bound1 ;
  }
  unsigned char Total1 = ( unsigned char )0 ;
  for ( ICount1 = 0 ; ICount1 < IncrementCap1 ; ICount1 ++ ) {
    if ( BPos1 > ICount1 ) {
      Total1 |= ( ( Start1[ APos1 ] & ( ( unsigned char )1 << ( 7 - BPos1 ) ) ) << ( BPos1 - ICount1 ) ) ;
    } else {
      Total1 |= ( ( Start1[ APos1 ] & ( ( unsigned char )1 << ( 7 - BPos1 ) ) ) >> ( ICount1 - BPos1 ) ) ;
    }
    APos1 += RowWidth1 ;
  }
  return Total1 ;
  // This returns an eight-bit character from the referenced character array starting at the specified bit in the specified row and proceeding downwards . For performance optimization , it has no bounds checking . Giving a position in any row beyond the eighth-to-last row shall likely cause a segmentation fault . This function caches values so that it can minimize integer division operations .
}
void RipDown2( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Iterations1 ) {
  int APos1 = ( RowPos1 ) * RowWidth1 + ( ColPos1 / 8 ) ;
  int BPos1 = ColPos1 % 8 ;
  int ICount1 ;
  int ICount2 ;
  unsigned char Total1 = ( unsigned char )0 ;
  ICount2 = 0 ;
  while ( ICount2 < Iterations1 ) {
    for ( ICount1 = 0 ; ICount1 <= 7 ; ICount1 ++ ) {
      if ( BPos1 > ICount1 ) {
        Total1 |= ( ( Start1[ APos1 ] & ( ( unsigned char )1 << ( 7 - BPos1 ) ) ) << ( BPos1 - ICount1 ) ) ;
      } else {
        Total1 |= ( ( Start1[ APos1 ] & ( ( unsigned char )1 << ( 7 - BPos1 ) ) ) >> ( ICount1 - BPos1 ) ) ;
      }
      APos1 += RowWidth1 ;
    }
    putchar( ( char )Total1 ) ;
    Total1 = ( unsigned char )0 ;
    ICount2 ++ ;
  }
  // This outputs eight-bit characters from the referenced character array starting at the specified bit in the specified row and proceeding downwards . For performance optimization , it has no bounds checking . Giving a position in any row beyond the eighth-to-last row shall likely cause a segmentation fault . This function caches values so that it can minimize integer division operations .
}
unsigned char RipUp1( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Bound1 ) {
  int APos1 = ( RowPos1 * RowWidth1 ) + ( ColPos1 / 8 ) ;
  int BPos1 = ColPos1 % 8 ;
  int ICount1 ;
  int IncrementCap1 = 8 ;
  if ( Bound1 < 8 ) { 
    IncrementCap1 = Bound1 ;
  }
  unsigned char Total1 = ( unsigned char )0 ;
  for( ICount1 = 0 ; ICount1 < IncrementCap1 ; ICount1 ++ ) {
    // This originally added 7 to RowPos1 before completing the other operations . This was removed in version 158 for better adherence to the stated functionality .
    if ( BPos1 > ICount1 ) {
      Total1 |= ( ( Start1[ APos1 ] & ( ( unsigned char )1 << ( 7 - BPos1 ) ) ) << ( BPos1 - ICount1 ) ) ;
    } else {
      Total1 |= ( ( Start1[ APos1 ] & ( ( unsigned char )1 << ( 7 - BPos1 ) ) ) >> ( ICount1 - BPos1 ) ) ;
    }
    APos1 -= RowWidth1 ;
  }
  return Total1 ;
  // This returns an eight-bit character from the referenced character array starting at the specified bit in the specified row and proceeding upwards . For performance optimization , it has no bounds checking . Giving a position in any row beyond the eighth-to-last row previously caused a segmentation fault . This function caches values so that it can minimize integer division operations .
}
void RipUp2( unsigned char* Start1 , int RowWidth1 , int RowPos1 , int ColPos1 , int Iterations1 ) {
  int APos1 = ( RowPos1 * RowWidth1 ) + ( ColPos1 / 8 ) ;
  int BPos1 = ColPos1 % 8 ;
  int ICount1 ;
  int ICount2 ;
  unsigned char Total1 = ( unsigned char )0 ;
  // This originally added 7 to RowPos1 before completing the other operations . This was removed in version 158 for better adherence to the stated functionality .
  ICount2 = 0 ;
  while ( ICount2 < Iterations1 ) {
    for( ICount1 = 0 ; ICount1 <= 7 ; ICount1 ++ ) {
      if ( BPos1 > ICount1 ) {
        Total1 |= ( ( Start1[ APos1 ] & ( ( unsigned char )1 << ( 7 - BPos1 ) ) ) << ( BPos1 - ICount1 ) ) ;
      } else {
        Total1 |= ( ( Start1[ APos1 ] & ( ( unsigned char )1 << ( 7 - BPos1 ) ) ) >> ( ICount1 - BPos1 ) ) ;
      }
      APos1 -= RowWidth1 ;
    }
    putchar( ( char )Total1 ) ;
    Total1 = ( unsigned char )0 ;
    ICount2 ++ ;
  }
  // This outputs eight-bit characters from the referenced character array starting at the specified bit in the specified row and proceeding upwards . For performance optimization , it has no bounds checking . Giving a position in any row beyond the eighth-to-last row previously caused a segmentation fault . This function caches values so that it can minimize integer division operations .
}
unsigned char* NumberFilter2( unsigned char* Input1 , int Cap1 , int Cap2 ) {
  int Count1 = 0 ;
  int Count2 = 0 ;
  unsigned char* Output1 = malloc( Cap1 ) ;
  while ( ( Input1[ Count1 ] > ( unsigned char )0 ) && ( Count1 < Cap1 ) && ( Count2 < Cap2 ) ) {
    if ( ( Input1[ Count1 ] >= ( unsigned char )48 ) && ( Input1[ Count1 ] <= ( unsigned char )58 ) ) {
      Output1[ Count2 ] = Input1[ Count1 ] ;
      Count2 ++ ;
    }
    Count1 ++ ;
  }
  Output1[ Count2 ] = ( unsigned char )0 ;
  return Output1 ;
  // This returns a pointer to a string of any decimal digits in the input string .
}
char* NumberFilter3( char* Input1 , int Cap1 , int Cap2 ) {
  int Count1 = 0 ;
  int Count2 = 0 ;
  char* Output1 = malloc( Cap1 ) ;
  while ( ( Input1[ Count1 ] > ( char )0 ) && ( Count1 < Cap1 ) && ( Count2 < Cap2 ) ) {
    if ( ( Input1[ Count1 ] >= ( char )48 ) && ( Input1[ Count1 ] <= ( char )58 ) ) {
      Output1[ Count2 ] = Input1[ Count1 ] ;
      Count2 ++ ;
    }
    Count1 ++ ;
  }
  Output1[ Count2 ] = ( char )0 ;
  return Output1 ;
  // This returns a pointer to a string of any decimal digits in the input string .
}
void PrintHelp1( ) {
  fprintf( stderr , "PBM_Processor_1.c ( 265 )\n" ) ;
  fprintf( stderr , "This programme takes a selection from an input pbm stream , transforms it as specified , and pastes it into an output pbm stream .\n" ) ;
  fprintf( stderr , "  --Rotate ( number of quarter turns of rotation between zero and three inclusively )\n" ) ;
  fprintf( stderr , "  --Flips ( ( 4 for a flip over y=x ) + ( 2 for a flip over the x-axis ) + ( 1 for a flip over the y-axis ) )\n" ) ;
  fprintf( stderr , "  --Width1 ( Input Width )\n" ) ;
  fprintf( stderr , "  --Height1 ( Input Height )\n" ) ;
  fprintf( stderr , "  --XOffset1 ( Input Horizontal Offset )\n" ) ;
  fprintf( stderr , "  --YOffset1 ( Input Vertical Offset )\n" ) ;
  fprintf( stderr , "  --XTotal1 ( Input Selection Width )\n" ) ;
  fprintf( stderr , "  --YTotal1 ( Input Selection Height )\n" ) ;
  fprintf( stderr , "  --Width2 ( Output Width )\n" ) ;
  fprintf( stderr , "  --Height2 ( Output Height )\n" ) ;
  fprintf( stderr , "  --XOffset2 ( Output Horizontal Offset )\n" ) ;
  fprintf( stderr , "  --YOffset2 ( Output Vertical Offset )\n" ) ;
  fprintf( stderr , "  --XTotal2 ( Output Selection Width )\n" ) ;
  fprintf( stderr , "  --YTotal2 ( Output Selection Width )\n" ) ;
  fprintf( stderr , "  --ManualDim1 ( 1 for setting arbitrary input dimensions )\n" ) ;
  fprintf( stderr , "  --ManualDim2 ( 1 for setting arbitrary output dimensions )\n" ) ;
  fprintf( stderr , "  --Help ( This prints the instructions and continues processing . )\n" ) ;
  fprintf( stderr , "  --help ( This prints the instructions and cancels image processing . )\n" ) ;
  #ifdef Support_64_1
  fprintf( stderr , "64-bit word optimizations are enabled .\n" ) ;
  #endif
}
// The new work begins .
int Up_Divide_1( int Dividend , int Divisor ) {
  int Temp ;
  Temp = ( Dividend / Divisor) ;
  if ( ( Dividend % Divisor ) > 0 ) {
    Temp ++ ;
  }
  return Temp ;
}
// int Calc_Square_1( int X_Total_1 , int Y_Total_1 ) {
//   return Up_Divide_1( XTotal1 , 8 ) * YTotal1 ;
// }
// This function expects Row_Width_2 to be the ceil( max( X_Total_1 , Y_Total_1 ) / 8 ) and the size of Output1 to be the product of Row_Width_2 and max( X_Total_1 , Y_Total_1 ) . It is long from finished at this point . It seems that it might be best to split the function into architecture-specific functions so as to avoid allocating unnecessary buffers .
int Pack_Square_1( char* Input_1 , char* Output_1 , unsigned int Row_Width_1 , unsigned int Row_Width_2 ,  unsigned int X_Offset_1 , unsigned int Y_Offset_1 , unsigned int X_Total_1 , unsigned int Y_Total_1 ) {
  int Mode_Width = 64 ;
  int Mode_Order = -1 ;
  // This might in some ways be better implemented at run-time since one sometimes runs 16-bit executables on 32-bit processors and 32-bit executables on 64-bit processors , but , in the interest of keeping a reasonable bound on the number of flying variables , it seems best to pick a mode at compile time .
  unsigned int Count_1 = 0 ;
  unsigned int Count_2 = 0 ;
  unsigned int Count_3 = 0 ;
  // As far as I know , Count_3 does not come into play in any of the active code as of version 193 . I will let the compiler eliminate it for now , though .
  unsigned int O_Pos_1 = 0 ;
  unsigned int A_Pos_1 = 0 ;
  unsigned int B_Pos_1 = 0 ;
  // With some clever coding , I could dramatically reduce the number of variables .
  unsigned int Pre_Offset_1 = 0 ;
  unsigned int Pre_Count_1 = 0 ;
  // I am not sure of the original purposes of these two variables . I think that they became irrelevant when we allowed the offset arguments to be specified in pixels .
  unsigned char Shift_Buffer_8_1 = 0 ;
  unsigned char Shift_Buffer_8_2 = 0 ;
  unsigned long int Shift_Buffer_32_1 = 0 ;
  unsigned long int Shift_Buffer_32_2 = 0 ;
  unsigned long long int Shift_Buffer_64_1 = 0 ;
  unsigned long long int Shift_Buffer_64_2 = 0 ;
  if ( ( Input_1 == NULL ) || ( Output_1 == NULL ) || ( Row_Width_1 == 0 ) || ( Row_Width_2 == 0 ) ) {
    return 1 ; // We eliminate unpleasant possibilities in advance .
  } else {
    // We compute how many bytes remain .
    switch ( Mode_Width ) {
      case 8 :
        if ( 1 == 1 ) { // Endianness does not matter for 8-bit operations .
          Count_2 = 0 ;
          B_Pos_1 = X_Offset_1 % 8 ;
          while ( Count_2 < Y_Total_1 ) {
            A_Pos_1 = ( Row_Width_1 * ( Y_Offset_1 + Count_2 ) ) + ( X_Offset_1 / 8 ) ;
            O_Pos_1 = ( Row_Width_2 * Count_2 ) ;
            if ( B_Pos_1 == 0 ) {
              // This loop operates in 8-bit mode .
              while ( X_Total_1 - Count_1 >= 8 ) {
                *( ( unsigned char * )( Output_1 + O_Pos_1 ) ) = *( ( unsigned char * )( Input_1 + A_Pos_1 ) ) ;
                A_Pos_1 += 1 ;
                Count_1 += 8 ;
                O_Pos_1 += 1 ;
              } // End 8-bit horizontal dimension while loop .
              if ( X_Total_1 - Count_1 >= 1 ) {
                *( ( unsigned char * )( Output_1 + O_Pos_1 ) ) = ( *( ( unsigned char * )( Input_1 + A_Pos_1 ) ) & ( ~ ( ( ( unsigned char )( 128 ) >> ( X_Total_1 - Count_1 - 1 ) ) - 1 ) ) ) ; // This gets the trailing sub-byte pixels .
                // Output_1[ O_Pos_1 ] = ( Input_1[ A_Pos_1 ] & ( ~ ( ( ( char )( 128 ) >> ( X_Total_1 - Count_1 - 1 ) ) - 1 ) ) ) ; // This does the same thing . I want to see whether these differ in execution time .
                A_Pos_1 += 1 ;
                Count_1 += X_Total_1 - Count_1 ; // I want to see whether the compiler manages to simplify this correctly .
                O_Pos_1 += 1 ;
              } // End 1-bit transfer if block .
            } else {
              while ( X_Total_1 - Count_1 >= 8 ) {
                Shift_Buffer_8_1 = ( ( ( *( ( char * )( Input_1 ) + A_Pos_1 ) ) << B_Pos_1 ) & ~( 1 << ( B_Pos_1 ) ) - 1 ) ;
                Shift_Buffer_8_2 = ( ( *( ( char * )( Input_1 ) + A_Pos_1 + 1 ) ) >> ( sizeof( long long int ) - B_Pos_1 ) & ( 1 << ( B_Pos_1 ) ) - 1 ) ;
                Shift_Buffer_8_1 |= Shift_Buffer_8_2 ;
                A_Pos_1 += 1 ;
                Count_1 += 8 ;
                *( ( char * )( Output_1 + O_Pos_1 ) ) = Shift_Buffer_8_1 ;
                O_Pos_1 += 1 ;
              } // End 8-bit horizontal dimension while loop .
            } // End B_Pos_1 if block .
          } // End vertical dimension while loop .
        }
      break ;
      case 64 :
        if ( Mode_Order == 1 ) { // This corresponds to a big-endian 64-bit architecture . This is the optimal architecture for processing portable bit-maps . Note that this code will produce extremely flawed output if run on a little-endian processor . In fact , right now , it will probably produce extremely flawed output on any processor since I have not yet tested it .
          Count_2 = 0 ;
          B_Pos_1 = X_Offset_1 % 8 ;
          while ( Count_2 < Y_Total_1 ) {
            A_Pos_1 = ( Row_Width_1 * ( Y_Offset_1 + Count_2 ) ) + ( X_Offset_1 / 8 ) ;
            O_Pos_1 = ( Row_Width_2 * Count_2 ) ;
            if ( B_Pos_1 == 0 ) {
              // This loop operates in 64-bit mode .
              while ( X_Total_1 - Count_1 >= 64 ) {
                // Shift_Buffer_64_1 = *( ( unsigned long long int * )( Input_1 ) + A_Pos_1 ) ;
                *( ( unsigned long long int * )( Output_1 + O_Pos_1 ) ) = *( ( unsigned long long int * )( Input_1 + A_Pos_1 ) ) ;
                A_Pos_1 += 8 ;
                Count_1 += 64 ;
                O_Pos_1 += 8 ;
              } // End 64-bit horizontal dimension while loop .
              // Begin code yanked from the 8-bit section .
              // This loop operates in 8-bit mode .
              while ( X_Total_1 - Count_1 >= 8 ) {
                *( ( unsigned char * )( Output_1 + O_Pos_1 ) ) = *( ( unsigned char * )( Input_1 + A_Pos_1 ) ) ;
                A_Pos_1 += 1 ;
                Count_1 += 8 ;
                O_Pos_1 += 1 ;
              } // End 8-bit horizontal dimension while loop .
              if ( X_Total_1 - Count_1 >= 1 ) {
                *( ( unsigned char * )( Output_1 + O_Pos_1 ) ) = ( *( ( unsigned char * )( Input_1 + A_Pos_1 ) ) & ( ~ ( ( ( unsigned char )( 128 ) >> ( X_Total_1 - Count_1 - 1 ) ) - 1 ) ) ) ; // This gets the trailing sub-byte pixels .
                // Output_1[ O_Pos_1 ] = ( Input_1[ A_Pos_1 ] & ( ~ ( ( ( char )( 128 ) >> ( X_Total_1 - Count_1 - 1 ) ) - 1 ) ) ) ; // This does the same thing . I want to see whether these differ in execution time .
                A_Pos_1 += 1 ;
                Count_1 += 1 ;
                O_Pos_1 += 1 ;
              }
              // End code yanked from the 8-bit section .
              // // This loop operates in 8-bit mode .
              // while ( X_Total_1 - Count_1 >= 8 ) {
              //   Shift_Buffer_64_1 = *( ( unsigned char * )( Input_1 ) + A_Pos_1 ) ;
              //   Output_1[ O_Pos_1 ] = Input_1[ A_Pos_1 ] ;
              //   A_Pos_1 += 1 ;
              //   Count_1 += 8 ;
              //   O_Pos_1 += 1 ;
              // }
            } else {
              while ( X_Total_1 - Count_1 >= 64 ) {
                Shift_Buffer_64_1 = ( ( ( *( ( unsigned long long int * )( Input_1 ) + A_Pos_1 ) ) << B_Pos_1 ) & ~( 1 << ( B_Pos_1 ) ) - 1 ) ;
                // ( ( *( ( unsigned long long int * )( Input_1 ) + A_Pos_1 ) ) << B_Pos_1 ) & ~( ( ( 1 << ( 8 - B_Pos_1 ) ) - 1 ) | ~( ( ( 1 << ( 16 - B_Pos_1 ) ) - 1 ) | ~( ( ( 1 << ( 24 - B_Pos_1 ) ) - 1 ) | ~( ( ( 1 << ( 32 - B_Pos_1 ) ) - 1 ) | ~( ( ( 1 << ( 40 - B_Pos_1 ) ) - 1 ) | ~( ( ( 1 << ( 48 - B_Pos_1 ) ) - 1 ) | ~( ( ( 1 << ( 56 - B_Pos_1 ) ) - 1 ) | ~( ( ( 1 << ( 64 - B_Pos_1 ) ) - 1 ) ) ;
                // I am not sure of precisely what this does and do not recall writing it . It seems to be flawed bit mask for little-endian operations . If not for the impeccable formatting , I would assume that somebody slipped this into the code when I was fantasizing about Plan 9 .
                Shift_Buffer_64_2 = ( ( *( ( unsigned long long int * )( Input_1 ) + A_Pos_1 + 1 ) ) >> ( sizeof( long long int ) - B_Pos_1 ) & ( 1 << ( B_Pos_1 ) ) - 1 ) ;
                Shift_Buffer_64_1 |= Shift_Buffer_64_2 ;
                A_Pos_1 += 8 ;
                Count_1 += 64 ;
                // Count_3 = 0 ;
                // while ( Count_2 < 8 ) {
                  // // This approach is sub-optimal , but the implementation is better than the complexity might suggest since the compiler collapses much of the expression .
                  // // Output_1[ O_Pos_1 ] = ( unsigned char )( ( Shift_Buffer_64_1 & ( ( ( unsigned long long int )( 0xFFU ) << ( 8 * 7 ) ) >> ( Count_2 * 8 ) ) ) >> ( Count_2 * 8 ) ) ;
                  // // This is also sub-optimal but ought to be a bit faster .
                  // Output_1[ O_Pos_1 ] = *( ( unsigned char * )( &Shift_Buffer_64_1 ) + Count_3 ) ;
                  // Count_3 ++ ;
                  // O_Pos_1 ++ ;
                // }
                // This seems to be fastest .
                *( ( unsigned long long int * )( Output_1 + O_Pos_1 ) ) = Shift_Buffer_64_1 ;
              } // End horizontal dimension while loop .
            } // End B_Pos_1 if block .
          } // End vertical dimension while loop .
        } else if ( Mode_Order == -1 ) {
          // We can rewrite the preceding block so as to flip the bytes in each 64-bit block before and after shifting . This might be slower than shifting individually .
        } // End ModeOrder if block .
      break ;
    }
  }
  return 0 ;
}
int Transpose_1( unsigned char * Input_1 , unsigned char * Output_1 ) {
// sizeof( Output_1 ) = 8 * sizeof( unsigned char ) ;
unsigned int B_1 ;
unsigned int B_2 ;
unsigned int B_3 ;
unsigned int B_4 ;
// We pack the starting registers .
// B_1 = ( ( unsigned int )( I_1 ) ) << 24 | ( ( unsigned int )( I_2 ) << 16 ) | ( ( unsigned int )( I_3 ) << 8 ) | ( ( unsigned int )( I_4 ) ) ;
// B_2 = ( ( unsigned int )( I_5 ) << 24 ) | ( ( unsigned int )( I_6 ) << 16 ) | ( ( unsigned int )( I_7 ) << 8 ) | ( ( unsigned int )( I_8 ) ) ;
B_1 = ( ( unsigned int )( Input_1[ 0 ] ) ) << 24 | ( ( unsigned int )( Input_1[ 1 ] ) << 16 ) | ( ( unsigned int )( Input_1[ 2 ] ) << 8 ) | ( ( unsigned int )( Input_1[ 3 ] ) ) ;
B_2 = ( ( unsigned int )( Input_1[ 4 ] ) << 24 ) | ( ( unsigned int )( Input_1[ 5 ] ) << 16 ) | ( ( unsigned int )( Input_1[ 6 ] ) << 8 ) | ( ( unsigned int )( Input_1[ 7 ] ) ) ;
// In the first set of operations , we transpose in two-bit squares .
// We put the odd rows into the first register and the even rows into the second register .
// B_3 = ( ( unsigned int )( I_1 ) << 24 ) | ( ( unsigned int )( I_3 ) << 16 ) | ( ( unsigned int )( I_5 ) << 8 ) | ( ( unsigned int )( I_7 ) ) ;
// B_4 = ( ( unsigned int )( I_2 ) << 24 ) | ( ( unsigned int )( I_4 ) << 16 ) | ( ( unsigned int )( I_6 ) << 8 ) | ( ( unsigned int )( I_8 ) ) ;
B_4 = ( ( B_1 & ( unsigned int )( 0xFFU ) ) << 16 ) | ( ( B_1 & ( unsigned int )( 0xFF0000U ) ) << 8 ) | ( ( B_2 & ( unsigned int )( 0xFFU ) ) ) | ( ( B_2 & ( unsigned int )( 0xFF0000U ) ) >> 8 ) ;
B_3 = ( ( B_1 & ( unsigned int )( 0xFF00U ) ) << 8 ) | ( ( B_1 & ( unsigned int )( 0xFF000000U ) ) ) | ( ( B_2 & ( unsigned int )( 0xFF00U ) ) >> 8 ) | ( ( B_2 & ( unsigned int )( 0xFF000000U ) ) >> 16 ) ;
// We now observe that we can transpose the two-bit squares by masking , shifting , and compositing .
B_1 = ( B_3 & ( unsigned int )( 0xAAAAAAAAU ) ) | ( ( B_4 & ( unsigned int )( 0xAAAAAAAAU ) ) >> 1 ) ;
B_2 = ( ( B_3 & ( unsigned int )( 1431655765U ) ) << 1 ) | ( B_4 & ( unsigned int )( 1431655765U ) ) ;
// We now repack .
B_4 = ( ( B_1 & ( unsigned int )( 0xFFU ) ) << 8 ) | ( ( B_2 & ( unsigned int )( 0xFFU ) ) ) | ( ( B_1 & ( unsigned int )( 0xFF0000U ) ) << 8 ) | ( ( B_2 & ( unsigned int )( 0xFF0000U ) ) ) ;
B_3 = ( B_1 & ( unsigned int )( 0xFF00U ) ) | ( ( B_2 & ( unsigned int )( 0xFF00U ) ) >> 8 ) | ( ( B_1 & ( unsigned int )( 0xFF000000U ) ) ) | ( ( B_2 & ( unsigned int )( 0xFF000000U ) ) >> 8 ) ;
// We transpose .
B_1 = ( B_3 & ( unsigned int )( 0xCCCCCCCCU ) ) | ( ( B_4 & ( unsigned int )( 0xCCCCCCCCU ) ) >> 2 ) ;
B_2 = ( ( B_3 & ( unsigned int )( 0x33333333U ) ) << 2 ) | ( B_4 & ( unsigned int )( 0x33333333U ) ) ;
// We repack .
B_4 = ( ( B_1 & ( unsigned int )( 0xFFFFU ) ) << 16 ) | ( ( B_2 & ( unsigned int )( 0xFFFFU ) ) ) ;
B_3 = ( B_1 & ( unsigned int )( 0xFFFF0000U ) ) | ( ( B_2 & ( unsigned int )( 0xFFFF0000U ) ) >> 16 ) ;
// We transpose .
B_1 = ( B_3 & ( unsigned int )( 0xF0F0F0F0U ) ) | ( ( B_4 & ( unsigned int )( 0xF0F0F0F0U ) ) >> 4 ) ;
B_2 = ( ( B_3 & ( unsigned int )( 0xF0F0F0FU ) ) << 4 ) | ( B_4 & ( unsigned int )( 0xF0F0F0FU ) ) ;
Output_1[ 0 ] = ( unsigned char )( ( B_1 & ( unsigned int )( 0xFF000000U ) ) >> 24 ) ;
Output_1[ 1 ] = ( unsigned char )( ( B_1 & ( unsigned int )( 0xFF0000U ) ) >> 16 ) ;
Output_1[ 2 ] = ( unsigned char )( ( B_1 & ( unsigned int )( 0xFF00U ) ) >> 8 ) ;
Output_1[ 3 ] = ( unsigned char )( ( B_1 & ( unsigned int )( 0xFFU ) ) ) ;
Output_1[ 4 ] = ( unsigned char )( ( B_2 & ( unsigned int )( 0xFF000000U ) ) >> 24 ) ;
Output_1[ 5 ] = ( unsigned char )( ( B_2 & ( unsigned int )( 0xFF0000U ) ) >> 16 ) ;
Output_1[ 6 ] = ( unsigned char )( ( B_2 & ( unsigned int )( 0xFF00U ) ) >> 8 ) ;
Output_1[ 7 ] = ( unsigned char )( ( B_2 & ( unsigned int )( 0xFFU ) ) ) ;
return 0 ;
}

// Soli Deo gloria .

